function [qrs_on_error_signals,t_off_error_signals] = test_qt_detector()
    
signals = [104 105 116 117 121 122 131 150 155 156 165 166 169 170 172 173 174 180 182 184 185 198 214 229 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 251 255 260 263 264 266 267 276 277 279 284];

%  signals = [235];

dummy_error_struct.not_found_ammount = 0;
dummy_error_struct.mean_error = 0;
dummy_error_struct.std_error = 0;

qrs_on_error_signals(1) = dummy_error_struct;
qrs_on_error_signals(1) = [];
t_off_error_signals(1) =  dummy_error_struct;
t_off_error_signals(1) =  [];

for itSenial=1:length(signals)
    
    record_name = strcat('sujeto', num2str(signals(itSenial)),'.mat')
    
    [x,qrs_beginning,t_end] = get_data_from_ptb(record_name);
    fs = 1000;
    channelAmmout = size(x);
    
    for itChannel=1:channelAmmout(2)
%     itChannel=6;
        [retQtIntervals, retQtpIntervals, qrs_beginning_calc,t_end_calc] = qt_detector(x(:,itChannel),fs);

        [qrs_on_error, t_off_error] = evaluate_qt_signal(qrs_beginning,t_end,qrs_beginning_calc,t_end_calc,fs);
        qrs_on_error_signals(itSenial,itChannel) = qrs_on_error;
        t_off_error_signals(itSenial,itChannel) = t_off_error;
    end
  end
end

%The arrays must be the same length than the original signal, with ones
%in the sample where the mark was detected
function [qrs_on_error,t_off_error] = evaluate_qt_signal(qrs_on1,t_off1,qrs_on2,t_off2,fs)

    [qrs_on_error_array,qrs_on_not_found_ammount] = calculate_error(qrs_on1,qrs_on2,floor(0.1*fs), floor(0.1*fs));
    
    if length(qrs_on_error_array) < 1
        error('Arrays were too off');
    end
    
    if nargin < 5
        error('Invalid number of args');
    end
    
    qrs_on_error.not_found_ammount = qrs_on_not_found_ammount;
    qrs_on_error.mean_error = mean(qrs_on_error_array)/fs;
    qrs_on_error.std_error = std(qrs_on_error_array)/fs;
    
   [t_off_error_array,t_off_not_found_ammount] = calculate_error(t_off1,t_off2,floor(0.1*fs), floor(0.1*fs));
    
    if length(t_off_error_array) < 1
        error('Arrays were too off');
    end
    
    t_off_error.not_found_ammount = t_off_not_found_ammount;
    t_off_error.mean_error = mean(t_off_error_array)/fs;
    t_off_error.std_error = std(t_off_error_array)/fs;
end

%Calculates errors between 2 arrays.
%param x first array
%param y second array
%param backward_lookup_window_length length of the interval to be searched  
%before the current peak(in samples)
%param forward_lookup_window_length length of the interval to be searched 
%after the current peak(in samples)
function [dist_array,not_found_ammount] = calculate_error(x,y,backward_lookup_window_length, forward_lookup_window_length)

if length(x) ~= length(y)
    error('x and y must be of identical length!');    
end

not_found_ammount = 0;
dist_array = [];
i=1;

while i <= length(x)
    
    while x(i) == 0 & i < length(x)
        i = i+1;
    end
    
    [yAnalizedInterval, yIntStart, yIntEnd] = subinterval(y, i - backward_lookup_window_length, i +forward_lookup_window_length);
    yMarkRelativePosition = find(yAnalizedInterval);
    
    if length(yMarkRelativePosition) < 1
        not_found_ammount = not_found_ammount+1;
    else
        yMarkPosition = yIntStart + yMarkRelativePosition(1)-1;
        dist_array(end+1) = abs(i - yMarkPosition);
    end
    
    i = i+1; 
end


end